import 'package:flutter/material.dart';
import 'package:flutterone/common/widget/star_rating.dart';
import 'package:flutterone/common/widget/dashed_line.dart';
import 'package:flutterone/page/category/Model/json_info_entity.dart';

class LDXCategoryItem extends StatelessWidget {
 final JsonInfoEntity jsonInfo;
  LDXCategoryItem(this.jsonInfo);
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(8),
      decoration: const BoxDecoration(
        border: Border (
           bottom: BorderSide(width: 1,color:Colors.grey),
        ),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          NameListHeader(),
          const SizedBox(height: 8),
          CreatContext(),
          const SizedBox(height: 8),
          creatFoot(),
        ],
      ) ,
    );
  }
 //1、封装列表内容
 Widget NameListHeader() {
    return Container(
      padding: EdgeInsets.fromLTRB(10, 5, 10, 5),
      decoration: BoxDecoration(
        color: const Color.fromARGB(255, 239, 205, 144),
        borderRadius: BorderRadius.circular(5),
      ),
      child: Text("${jsonInfo.nickname}",style: const TextStyle(fontSize: 20,color: Color.fromARGB(255, 131, 95, 36)),),
    );
 }
 Widget CreatContext() {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        CreatImage(),
        SizedBox(width: 8,),
        CreatText(),
        SizedBox(width: 8,),
        creatLine(),
        SizedBox(width: 8,),
        creatWish(),
      ],
    );
 }
 Widget CreatImage() {
    return ClipRRect(
      borderRadius: BorderRadius.circular(5),
      child: Image.network("${jsonInfo.imageName}",height: 200,width: 150,fit: BoxFit.cover,),
    );
 }
 Widget CreatText() {
    return Expanded(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          creatTitle(),
          SizedBox(height: 8,),
          creatInfoRate(),
          SizedBox(height: 8,),
          creatInfoDesc(),
        ],
      ),
    );
 }
 Widget creatTitle() {
   return Text.rich (
     TextSpan(
       children: [
         WidgetSpan(child: Icon(Icons.play_circle_fill , color: Colors.redAccent,size: 20,)),
         WidgetSpan(child: Text("${jsonInfo.nickname}",style: TextStyle(fontSize: 22),),),
         WidgetSpan(child: Text("(${jsonInfo.registerDate})",style: TextStyle(color: Colors.grey,fontSize: 14),),),
       ],
     )
   );
 }
 Widget creatInfoRate() {
    
    return FittedBox(
      child: Row(
        children: [
          LDXStarRating(rating: 8.5,size: 20,),
          SizedBox(width: 6,),
          Text("8.5"),
        ],
      ),
    );
 }
 Widget creatInfoDesc() {
    final genresString = jsonInfo.courses?.join(" ");
    final directorString = jsonInfo.computer?.brand;
    
    return Text(
      "$genresString / $directorString",
      maxLines: 3,
    );
 }
 //虚线
 Widget creatLine() {
    return Container(
      height: 100,
      child: LDXDashedLine(
        axis: Axis.vertical,
        dashedWidth: 1,
        dashedHeight: 6,
        count: 10,
        color: Colors.redAccent,
      ),
    );
 }
 //想看
 Widget creatWish(){
    return Container(
      height: 100,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Icon(Icons.heart_broken,size: 35,color: Colors.orange,),
          Text("想看",style: TextStyle(fontSize: 16,color: Colors.orange),),
        ],
      ),
    );
 }
 //尾部内容布局
Widget creatFoot() {
  final directorString = jsonInfo.computer?.price;
  return Container(
    width: double.infinity,//宽度拉伸到最大
    height: 35,
    padding: EdgeInsets.all(8),
    decoration: BoxDecoration(
        color: Colors.grey.shade300,
        borderRadius: BorderRadius.circular(6),
      ),
    child: Text("$directorString",style: TextStyle(fontSize: 16),),
    );
}

}
